package com.hunt.controller;

import com.hunt.model.entity.LecturerArticle;
import com.hunt.model.entity.LecturerVideo;
import com.hunt.service.LecturerZoneService;
import com.hunt.util.FilterHtmlUtil;
import com.hunt.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Author: ww
 * @Date : 2020/9/22 16:15
 */

@Api(value = "手机app端,讲师专区")
@Controller
@RequestMapping(path = "/app/lecturerZone")
public class LecturerZoneController extends BaseController {

    @Autowired
    private LecturerZoneService lecturerZoneService;

    @ApiOperation(value = "查询讲师视频", httpMethod = "GET", produces = "application/json", response = Result.class)
    @ResponseBody
    @RequestMapping(value = "getLecturerVideoByPositionSize", method = RequestMethod.GET)
    public Result getLecturerVideoByPositionSize(@RequestParam(value = "position", defaultValue = "0") Integer position,
                                                 @RequestParam(value = "size", defaultValue = "1") Integer size,
                                                 @RequestParam(value = "type",required = false) String type) {
        //参数讲师编号:  0:null  1:实战技巧 2:底部形态 3:经典课程 4:四维战法 5:宣传片
        List<LecturerVideo> videoByPositionList = lecturerZoneService.getLecturerVideoByPositionSize(position, size, type);
        return Result.success(videoByPositionList);
    }

    /**
     * 早中晚评
     *
     * @param position
     * @param size
     * @return
     */
    @ApiOperation(value = "查询讲师评论", httpMethod = "GET", produces = "application/json", response = Result.class)
    @ResponseBody
    @RequestMapping(value = "findLecturerArticleByPositionSize", method = RequestMethod.GET)
    public Result findLecturerArticleByPositionSize(@RequestParam(value = "position", defaultValue = "0") int position,
                                                    @RequestParam(value = "size", defaultValue = "10") int size) {

        List<LecturerArticle> lecturerArticleList = lecturerZoneService.findLecturerArticleByPositionSize(position, size);

            if (null == lecturerArticleList || lecturerArticleList.size() == 0) {
                return Result.success(lecturerArticleList);
            } else {
                for (LecturerArticle lecturerArticle : lecturerArticleList) {
                    String contentFormat = FilterHtmlUtil.Html2Text(lecturerArticle.getContent());
                    if (contentFormat.length() >= 200){
                        lecturerArticle.setContent(contentFormat.substring(0,200));
                    }else{
                        lecturerArticle.setContent(contentFormat);
                    }
                }
            }
            return Result.success(lecturerArticleList);
    }


    /**
     * 早中晚评详情
     * @param id
     * @return
     */
    @ApiOperation(value = "查询讲师评论详情", httpMethod = "GET", produces = "application/json", response = Result.class)
    @ResponseBody
    @RequestMapping(value = "findArticleDetailById", method = RequestMethod.GET)
    public Result findArticleDetailById(@RequestParam(value = "id", defaultValue = "0") String id) {
        LecturerArticle detailById = lecturerZoneService.findArticleDetailById(id);

        String contentFormat = FilterHtmlUtil.LecturerDetail2Text(detailById.getContent());
        String titleFormat = FilterHtmlUtil.LecturerDetail2Text(detailById.getTitle());
        detailById.setContent(contentFormat);
        detailById.setTitle(titleFormat);

        return Result.success(detailById);
    }
}
